package com.bootdo.collector.task;

import com.bootdo.collector.domain.PWarn;
import com.bootdo.screen.domain.PswarningDO;
import com.bootdo.screen.service.PswarningService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class PublishWarnJob  implements Job {

    @Autowired
    private JdbcTemplate ThirdJdbcTemplate;

    @Autowired
    private PswarningService pswarningService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 舆情预警
        List<PWarn> dwarns = ThirdJdbcTemplate.query("select id,warnname,flag,warn_time from t_warn_set where departid=0 or departid=1", new BeanPropertyRowMapper<>(PWarn.class));
        for (PWarn depart:dwarns) {
               PswarningDO pswarn = new PswarningDO();
               pswarn.setId(depart.getId());
               pswarn.setTitle(depart.getWarnname());
               if (depart.getFlag()==0) {
                   pswarn.setStatus("正常");
               } else {
                   pswarn.setStatus("预警");
                   pswarn.setDate(depart.getWarn_time());
               }
            pswarningService.saveUpdate(pswarn);
        }

    }
}
